package com.meng.imrongyun.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.meng.baselibrary.adapter.BaseRecycleViewAdapter;
import com.meng.imrongyun.R;

import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.MessageContent;
import io.rong.message.TextMessage;

/**
 * Created by Administrator on 2017/5/15.
 */

public class SubConversationAdapter extends BaseRecycleViewAdapter<Conversation> {
    public SubConversationAdapter(Context context) {
        super(context);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
        return new ItemHolder(getInflater().inflate(R.layout.item_recent_conversation, null));
    }

    @Override
    protected void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemHolder itemHolder = (ItemHolder) holder;
        Log.d("SubConversationAdapter", "getTargetId:" + getItem(position).getTargetId());
        Conversation conversation = getItem(position);
        itemHolder.userIcon.setImageURI(conversation.getPortraitUrl());
        itemHolder.nicknameTv.setText(conversation.getSenderUserId());
        MessageContent messageContent = conversation.getLatestMessage();
        Log.d("SubConversationAdapter", ((TextMessage) messageContent).getContent());
        itemHolder.lastMsgTv.setText(((TextMessage)messageContent).getContent());
    }

    class ItemHolder extends ItemViewHolder {
        SimpleDraweeView userIcon;
        TextView nicknameTv;
        TextView lastMsgTv;
        public ItemHolder(View itemView) {
            super(itemView);
            userIcon = (SimpleDraweeView) itemView.findViewById(R.id.user_icon);
            nicknameTv = (TextView) itemView.findViewById(R.id.nickname_tv);
            lastMsgTv = (TextView) itemView.findViewById(R.id.lastmsg_tv);
        }
    }
}
